package com.easyJava.utils;


import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ZhangYK
 * @version 8.0
 * @title PropertiesUtils
 * @description
 * @create 2024/11/13 21:59
 */
public class PropertiesUtils {
    private static Properties props = new Properties();
    private static Map<String,String> PROPER_MAP = new ConcurrentHashMap<>();

    static {
        InputStream is = null;
        try{
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
            props.load(is);
            Iterator<Object> iterator = props.keySet().iterator();
            while (iterator.hasNext()){
                String key = (String) iterator.next();
                PROPER_MAP.put(key,props.getProperty(key));
            }
        }catch (Exception e){

        }finally {
            if (is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }else {
                System.out.println("没有获取流！");
            }
        }
    }

    public static String getString(String key){
        return PROPER_MAP.get(key);
    }

    public static void main(String[] args) {
        System.out.println(getString("db.driver"));
    }
}
